package com.pomr.service.sys.Impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import com.pomr.entity.UserEffect;
import com.pomr.model.sys.*;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.pomr.dao.base.BaseDao;
import com.pomr.model.menu.EquipmentCondition;
import com.pomr.model.menu.EquipmentKind;
import com.pomr.model.menu.EquipmentStatus;
import com.pomr.model.menu.HealthCondition;
import com.pomr.model.menu.Industry;
import com.pomr.model.menu.Marriage;
import com.pomr.model.menu.NetworkOperator;
import com.pomr.model.menu.Relation;
import com.pomr.model.menu.Sex;
import com.pomr.util.common.CommonData;

import net.sf.ehcache.util.PropertyUtil;
@Service
public class InternationalServiceImpl implements InitializingBean{
	@Autowired
	@Qualifier("baseDaoImpl")
	private BaseDao baseDao;

	@Override
	public void afterPropertiesSet() throws Exception {
		System.err.println("加载公共数据。。。");
		System.err.println("加载健康状况信息");
		List<HealthCondition> healthConditions = baseDao.findByHql("from HealthCondition");
		CommonData.data.put("HealthCondition", healthConditions);
		System.err.println("加载职业信息");
		List<Industry> industrys = baseDao.findByHql("from Industry");
		CommonData.data.put("Industry", industrys);
		System.err.println("加载婚姻状况");
		List<Marriage> marriages = baseDao.findByHql("from Marriage");
		CommonData.data.put("Marriage", marriages);
		System.err.println("加载性别信息");
		List<Sex> sexs = baseDao.findByHql("from Sex");
		System.out.println(sexs.size());
		CommonData.data.put("Sex", sexs);
		System.err.println("加载省信息");
		List<Province> provinces = baseDao.findByHql("from Province p");
		CommonData.data.put("Province", provinces);
		System.err.println("加载市信息");
		List<City> citys = baseDao.findByHql("from City");
		CommonData.data.put("City", citys);
		System.err.println("加载县信息");
		List<Coutry> coutrys = baseDao.findByHql("from Coutry");
		CommonData.data.put("Coutry", coutrys);
		System.err.println("加载家庭角色信息");
		List<Relation> relations = baseDao.findByHql("from Relation");
		CommonData.data.put("Relation", relations);
		System.err.println("加载网络运行商信息");
		List<NetworkOperator> networks = baseDao.findByHql("from NetworkOperator");
		CommonData.data.put("NetworkOperator", networks);
		System.err.println("加载设备状态信息");
		List<EquipmentStatus> equipmentStatus = baseDao.findByHql("from EquipmentStatus");
		CommonData.data.put("EquipmentStatus", equipmentStatus);
		System.err.println("加载设备状况信息");
		List<EquipmentCondition> equipmentCondition = baseDao.findByHql("from EquipmentCondition");
		CommonData.data.put("EquipmentCondition", equipmentCondition);
		System.err.println("加载设备种类信息");
		List<EquipmentKind> equipmentKind = baseDao.findByHql("from EquipmentKind");
		CommonData.data.put("EquipmentKind", equipmentKind);
		System.err.println("加载系统配置信息");
		Properties props = new Properties();
        InputStream in = null;
        try {
        	// 第一种，通过类加载器进行获取properties文件流
            in = PropertyUtil.class.getClassLoader().getResourceAsStream("config.properties");
            props.load(in);
            if(props != null){
            	Map<String, Object> map = new HashMap<String, Object>();
            	map.put("token.date", props.getProperty("token.date"));
            	CommonData.data.put("config", map);
            }
        } catch (FileNotFoundException e) {
            System.out.println("jdbc.properties文件未找到");
        } catch (IOException e) {
        	System.out.println("出现IOException");
        } finally {
            try {
                if(null != in) {
                    in.close();
                }
            } catch (IOException e) {
                System.out.println("jdbc.properties文件流关闭出现异常");
            }
        }
        System.out.println("加载properties文件内容完成...........");
        System.out.println("properties文件内容：" + props);
	}

}
